package fr.oz.mobile.home 
{
	import caurina.transitions.Tweener;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import fr.oz.core.events.ModuleEvent;
	import fr.oz.mobile.common.BGLayer_FC;
	import fr.oz.mobile.common.horloge.Horloge;
	import fr.oz.mobile.common.ui.DragDropableList;
	import fr.oz.mobile.common.ui.GradientMask;
	import fr.oz.mobile.module.IModule;
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class Home extends Sprite implements IModule
	{
		private var homeNav:HomeNav;
		private var horloge:Horloge;
		private var bg:BGLayer_FC;
		private var drag_zone:Sprite;
		private var container:DragDropableList;
		private var container_mask:GradientMask;
		
		public function Home() 
		{
			bg = new BGLayer_FC();
			bg.y = 230;
			bg.alpha = 0;
			addChild(bg);
			
			horloge = new Horloge();
			addChild(horloge);
			addEventListener(Event.ADDED_TO_STAGE, init);
			
			container = new DragDropableList();
			addChild(container);
			
			homeNav = new HomeNav();
			container.addChild(homeNav);
			
			Tweener.addTween(bg,{alpha:1, time:.5});
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
			horloge.y = 40;
			horloge.x = (stage.stageWidth >> 1) >> 0;
			
			drag_zone = new Sprite()
			drag_zone.graphics.beginFill(0xFF0000, 0);
			drag_zone.graphics.drawRect(0, 0, stage.stageWidth, container.height);
			drag_zone.mouseEnabled = false;
			drag_zone.graphics.endFill();
			container.addChild(drag_zone);
			
			container_mask = new GradientMask(30, new Rectangle(0, stage.stageHeight*.5 - 55, stage.stageWidth, stage.stageHeight*.5 + 55));
			addChild(container_mask);
			
			container.cacheAsBitmap = true;
			container_mask.cacheAsBitmap = true;
			container_mask.mouseEnabled = false;
			container.mask = container_mask;
			
			container.y = stage.stageHeight >> 1;
			
			container.setLimits(stage.stageHeight >> 1, stage.stageHeight>>1, container.height);
		}
		
		private function dispose(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
			removeChild(bg);
			bg = null;
			removeChild(horloge);
			horloge = null;
			container.removeChild(homeNav);
			homeNav = null;
			container.removeChild(drag_zone);
			drag_zone = null;
			removeChild(container);
			container = null;
			removeChild(container_mask);
			container_mask = null;
		}
		
		
		/* INTERFACE fr.oz.mobile.module.IModule */
		
		public function resize():void
		{
			
		}
		
		public function activeView():void
		{
			
		}
		
		public function removeView():void
		{
			Tweener.addTween([ horloge, homeNav], { alpha:0, time:1} );
			Tweener.addTween(bg, { alpha:0, time:1, onComplete:killView} );
		}
		
		private function killView():void
		{
			dispatchEvent(new Event(Event.CLOSE));
		}
		
		public function goBack():Boolean
		{
			return false;
		}
		
	}

}